//
//  XMGTagCell.m
//  BuDeJie19
//
//  Created by hjj on 2016/12/3.
//  Copyright © 2016年 hjjuny. All rights reserved.
//

#import "XMGTagCell.h"
#import <UIImageView+WebCache.h>
#import "XMGSubTagItem.h"
@interface XMGTagCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameView;
@property (weak, nonatomic) IBOutlet UILabel *numView;

@end

@implementation XMGTagCell
/*
    1.图片变成圆角
    2.订阅数字
 */

// 当cell要显示的时候，系统会自动调用setFrame，给cell设置尺寸和位置
- (void)setFrame:(CGRect)frame
{
//    NSLog(@"%@",NSStringFromCGRect(frame));
    frame.size.height -= 10;
    frame.origin.y += 10;
    frame.origin.x += 10;
    frame.size.width -= 20;

    [super setFrame:frame];
}
- (void)setItem:(XMGSubTagItem *)item
{
    _item = item;
    
    [_iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    _nameView.text = item.theme_name;
    
    // 处理订阅数字
    item.sub_number = @"30000";
    CGFloat num = [item.sub_number floatValue];
   
    NSString *numStr = [NSString stringWithFormat:@"%@人订阅",item.sub_number];
    if (num > 10000) {
        num = num / 10000.0;
        numStr = [NSString stringWithFormat:@"%.1f万人订阅",num];
        numStr = [numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }
    
    _numView.text = numStr;
    
}

+ (instancetype)cell
{
    return [[[NSBundle mainBundle] loadNibNamed:@"XMGTagCell" owner:nil options:nil] firstObject];
}

// 当控件从xib加载完成就会调用
// 调用一次
- (void)awakeFromNib {
    [super awakeFromNib];
    
//    _iconView.layer.cornerRadius = _iconView.xmg_width * 0.5;
//    
//    // 超出主层就会裁剪掉
//    _iconView.layer.masksToBounds = YES;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
